import { defineStore } from "pinia";
import { computed, ref } from "vue";

export const useAlertsStore = defineStore("alerts", {
  // 状态变量
  state() {
    return {
      count: 0,
      firstName: "li",
      lastName: "jack",
    };
  },
  // 计算属性
  getters: {
    fullName() {
      return `${this.lastName} ${this.firstName}`;
    },
  },
  // 方法
  actions: {
    increment() {
      this.count++;
    },
  },
});

export const useUsersStore = defineStore("users", () => {
  // state
  const count = ref(0);
  // getter
  const firstName = ref("zhang");
  const lastName = ref("jack");
  const fullName = computed(() => `${lastName.value} ${firstName.value}`);
  // action
  function increment() {
    count.value++;
  }
  return {
    count,
    fullName,
    increment,
  };
});

export const userFormsStore = defineStore("forms", {
  state() {
    return {
      username: "jack",
    };
  },
});
